@ECHO OFF
ECHO Source Analysis Policy Release Builder
ECHO Copyright (c) Jeff Winn. All rights reserved.
ECHO.

IF /I "%1"=="/?" GOTO ShowSyntax
IF /I "%1"=="/help" GOTO ShowSyntax
IF /I "%1"=="-?" GOTO ShowSyntax

REM *******************************************************
REM * CONFIGURATION
REM *******************************************************

SET SKIPPACK=false

REM *****************************************************************
REM DO NOT MODIFY THE CONTENTS OF THIS FILE BELOW THIS POINT!!
REM *****************************************************************

SET BATCHOICE=
SET KEYFILE=.\Public.snk
SET RELEASEKEYFILE=G:\PrivateKeys\Winnster.snk
SET FXFOLDER=%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319

REM *****************************************************************
REM * INITIALIZE
REM *****************************************************************

IF "%DEVENVDIR%" == "" GOTO NeedSDKPrompt
IF NOT "%2" == "" (SET RELEASEKEYFILE=%2)

:Initialize

IF /I "%1" == "/testonly" GOTO SetTestOnly
IF /I "%1" == "/skiptest" (SET SKIPTEST=true)
IF /I "%1" == "/skiptests" (SET SKIPTEST=true)
IF /I "%1" == "/skipdocs" (SET SKIPDOCS=true)
IF /I "%1" == "/skipdoc" (SET SKIPDOCS=true)
IF /I "%1" == "/skippack" (SET SKIPPACK=true)
IF /I "%1" == "1" (SET BATCHOICE=1)
IF /I "%1" == "2" (SET BATCHOICE=2)
IF /I "%1" == "" GOTO EndInit
SHIFT

GOTO Initialize

:EndInit

IF NOT "%BATCHOICE%" == "" GOTO SkipBuildSelection

ECHO ATTENTION! For your safety, please understand this build project may use 
ECHO custom MSBuild tasks during the build process.
ECHO.
ECHO 1. NON-OFFICIAL release build.
ECHO 2. OFFICIAL release build. This option requires a specific strong key file.
ECHO 3. ABORT!
ECHO.
CHOICE /C:123 /N /D:3 /T:30 /M "Please enter a build option (1/2/3):"

SET BATCHOICE=%ERRORLEVEL%

:SkipBuildSelection

IF %BATCHOICE% == 2 GOTO SetOfficialRelease
IF %BATCHOICE% == 3 GOTO AbortRequested

SET SKIPDOCS=true
SET SKIPPACK=true

GOTO PerformBuild



:SetTestOnly

SET SKIPTEST=false
SET SKIPDOCS=true
SET SKIPPACK=true

:SetOfficialRelease

SET KEYFILE=%RELEASEKEYFILE%
IF NOT EXIST "%KEYFILE%" GOTO MissingSNK
GOTO PerformBuild




:PerformBuild

"%FXFOLDER%\MSBuild.exe" .\build.proj /p:AssemblyOriginatorKeyFile="%KEYFILE%" /p:SkipPackage=%SKIPPACK% /fl /v:diag

GOTO ExitBatch




:ShowSyntax

ECHO Syntax: make.bat [options]
ECHO.
ECHO Options:
ECHO      /skippack	- Forces the packaging process to be skipped.
ECHO.
GOTO ExitBatch




:AbortRequested

ECHO.
ECHO Aborting the build process as requested.
ECHO.

GOTO ExitBatch



:NeedSDKPrompt

ECHO.
ECHO *******************************************
ECHO * ABORTING! VISUAL STUDIO SDK PROMPT
ECHO *******************************************
ECHO.
ECHO Aborting the build process. This batch file must be executed within a 
ECHO Visual Studio command prompt.
ECHO.

GOTO ExitBatch




:MissingSNK

ECHO.
ECHO *******************************************
ECHO * ABORTING! MISSING SNK FILE
ECHO *******************************************
ECHO.
ECHO Aborting the build process. The private key could not be found. Please verify
ECHO the USB key is inserted in the build machine or choose the non-official 
ECHO release build.
ECHO.
ECHO KEYFILE: %KEYFILE%
ECHO.

GOTO ExitBatch




:ExitBatch